#ifndef CNETWORK_H
#define CNETWORK_H

#include <QObject>

#include <QTcpServer>
#include <QTcpSocket>

#include <QList>
#include <QMap>

#include "../Models/MClient.h"

#include "CDataBase.h"

class CNetwork : public QObject
{
    Q_OBJECT
    private:
        QTcpServer *server;
        QMap <QTcpSocket*, MClient*> clients;

        CDataBase *c_database;

    public:
        CNetwork();
        ~CNetwork();

        // Getters
        QTcpServer* get_server();
        QMap <QTcpSocket*, MClient*> get_clients();

    signals:
        void new_chat_client(QTcpSocket*);
        void is_receiving();
        void login(MClient*);
        void discoo();
        void discoo(QTcpSocket *);

        void receive_chat(QTcpSocket*);

        void authentification_ok(QString, QString);
        void authentification_failed(QString, QString);

    public slots:
        bool start_listen(quint16 port);
        QTcpSocket* wait_connection();

        void send(QTcpSocket* socket, QString message);
        QString receive(QTcpSocket* socket);

        void select_action();
        void disco();
};

#endif // CNETWORK_H
